package cn.com.fuhuitong.app

import android.app.Application
import androidx.multidex.MultiDex
import cn.com.fuhuitong.main.access.entity.UserInfoEntity
import cn.com.fuhuitong.utils.JsonUtils
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPStaticUtils
import com.google.gson.JsonSyntaxException
import com.tencent.smtt.sdk.QbSdk

class BaseApplication : Application() {


    companion object {
        lateinit var INSTANCE: Application

        fun userInfo(): UserInfoEntity? = try {
            JsonUtils.stringToObject(
                SPStaticUtils.getString(AppConstance.BUNDLE_USER_INFO),
                UserInfoEntity::class.java

            )
        } catch (e: JsonSyntaxException) {
            null
        }

        fun userToken(): String = SPStaticUtils.getString(AppConstance.BUNDLE_USER_TOKEN)
    }

    override fun onCreate() {
        super.onCreate()

        //获取Application
        INSTANCE = this

        MultiDex.install(this)

        //初始化路由
//        ARouter.openLog()
//        ARouter.openDebug()
        ARouter.init(this)

        QbSdk.initX5Environment(this, object : QbSdk.PreInitCallback {
            override fun onCoreInitFinished() = Unit
            override fun onViewInitFinished(p0: Boolean) {
                LogUtils.e("加载内核是否成功:$p0")
            }
        })
        QbSdk.setDownloadWithoutWifi(true)
    }
}